package tv.geir.slackspace.server;

import java.io.Serializable;
import java.rmi.RemoteException;

import net.jini.core.lease.LeaseDeniedException;
import net.jini.core.lease.UnknownLeaseException;
import net.jini.id.Uuid;

/**
 * Lease information for an entry
 * 
 * @author Geir Gullestad Pettersen
 *
 */
public class ServerLease implements Serializable {

	private static final long serialVersionUID = 1L;
	private long leaseTime;
	private Uuid leaseId;
	private long leaseCreatedTime;
	
	
	
	public ServerLease(long leaseTime, long leaseCreatedTime, Uuid id ) {
		super();
		this.leaseTime = leaseTime;
		this.leaseCreatedTime = leaseCreatedTime;
		this.leaseId = id;
	}

	public boolean isExpired() {
		return System.currentTimeMillis() > getExpireTime();
	}
	
	public long getExpireTime() {
		return Math.max( leaseCreatedTime + leaseTime, leaseTime );
	}
	
	public long getLeaseCreatedTime() {
		return leaseCreatedTime;
	}

	public void setLeaseCreatedTime(long leaseCreatedTime) {
		this.leaseCreatedTime = leaseCreatedTime;
	}

	public Uuid getLeaseId() {
		return leaseId;
	}

	public void setLeaseId(Uuid leaseId) {
		this.leaseId = leaseId;
	}

	public long exiresInMillis() {
		return getExpireTime() - System.currentTimeMillis();		
	}
	
	public long getLeaseTime() {
		return leaseTime;
	}


	public void renew(long arg0) throws LeaseDeniedException,
			UnknownLeaseException, RemoteException {

	}


	
}
